package com.grantheath.erebus.core
{
	import com.grantheath.erebus.controller.initializationCommands.ErebusInitializeProxiesCommand;
	import com.grantheath.erebus.controller.initializationCommands.ErebusInitializeAppStageCommand;
	import com.grantheath.erebus.view.interfaces.IErebusPage;
	import com.grantheath.erebus.core.interfaces.IErebusFacade;
	import com.grantheath.erebus.model.enum.notifications.ErebusInitializationNotifications;
	import com.grantheath.erebus.controller.initializationCommands.ErebusInitializeURLHandeling;
	import com.grantheath.erebus.controller.initializationCommands.ErebusInitializeQueuesCommand;

	import org.puremvc.as3.patterns.facade.Facade;

	import flash.display.DisplayObject;

	/**
	 * @author grantheath
	 */
	public class ErebusFacade extends Facade implements IErebusFacade 
	{
		public function ErebusFacade()
		{
			super();
		}
		
		//initialize controller
		override protected function initializeController() : void
		{
			super.initializeController();
			registerCommand(ErebusInitializationNotifications.INITIALIZE_PROXIES, ErebusInitializeProxiesCommand);
			registerCommand(ErebusInitializationNotifications.INITIALIZE_APP_STAGE, ErebusInitializeAppStageCommand);
			registerCommand(ErebusInitializationNotifications.INITIALIZE_URL_HANDELING, ErebusInitializeURLHandeling);
			registerCommand(ErebusInitializationNotifications.INITIALIZE_QUEUES, ErebusInitializeQueuesCommand);
		}

		//startup function
		public function startUp(appStage : DisplayObject) : void
		{
			sendNotification(ErebusInitializationNotifications.INITIALIZE_CLASS_REFERENCE_PROXY, appStage);
			sendNotification(ErebusInitializationNotifications.INITIALIZE_APP_STAGE);
			sendNotification(ErebusInitializationNotifications.INITIALIZE_PROXIES);
		}
		
		//hooks so that loaded pages can acces the facade
		public function registerPageStartupCommand(startupNotification : String, startupCommand : Class) : void
		{
			registerCommand(startupNotification, startupCommand);
		}

		public function startupPage(startupNotification : String, page : IErebusPage) : void
		{
			sendNotification(startupNotification, page);
		}
		
		//hooks so that unloaded pages can unitialize their proxies, mediators,etc.
		public function registerPageUnitializeCommand(uninitializeNotification : String, uninitializeCommand : Class) : void
		{
			registerCommand(uninitializeNotification, uninitializeCommand);
		}

		public function uninitializePage(uninitializeNotification : String, page : IErebusPage = null) : void
		{
			sendNotification(uninitializeNotification, page);
		}
	}
}
